			$table = $('.table');
			$level = $('.level');
			var cardNum = 4;
			var boxWidth = 80;
			var boxHeight = 120;
			var num = new Array();
			var timeStill,minute=10;
			var pre;
			var condition = 0;
			var startTrans;
			$time = $('.time');
			var cacuTime, startWait = null;		
			//卡片背面的点击事件
			function launched() {
				var hasPi = 0;
				var ifContinue = 0;
				$('.cardbg').each(function(i) {
					$(this).click(function() {
						if(ifContinue == 0) {
							pre = i;
						}
						turnCard(180, $allcardbg[i], -10);
						turnCard(0, $allcard[i], 10);

						if(ifContinue > 0) {
							if($($allcard[i]).attr('number') != $($allcard[pre]).attr('number')) {
								startTrans = setTimeout(function() {
									turnCard(180, $allcard[i], -10);
									turnCard(0, $allcardbg[i], 10);

								}, 600);

							} else {
								ifContinue = -1;
								hasPi++;
								$($allcard[i]).remove();
								$($allcardbg[i]).remove();
								$($allcard[pre]).remove();
								$($allcardbg[pre]).remove();
							}
						}
						if(hasPi == (cardNum / 2)) {
							var word = "恭喜通关!";
							end(word);
						}
						ifContinue++;
					});
				});
				//卡片正面的点击事件
				$('.card').each(function(i){
					$(this).click(function(){
						ifContinue=0;
						turnCard(180, $allcard[i], -10);
						turnCard(0, $allcardbg[i], 10);
					})
				})
			}
			
			//等级设置，启动游戏
			var basisIn=[{"cardNum":"4","minute":"10","timeStill":"2000"},
			{"cardNum":"16","minute":"20","timeStill":"5000"},
			{"cardNum":"32","minute":"40","timeStill":"8000"},
			{"cardNum":"64","minute":"70","timeStill":"12000"},];
			$level.each(function(i) {
				$(this).click(function() {
					cardNum=(basisIn[i].cardNum);
					minute=basisIn[i].minute;
					timeStill=basisIn[i].timeStill;
					if(i<3){
						$($table).css({
								'width': '70%',
								'height': '65%'
							});
					}
					else{
						$($table).css({
								'width': '96%',
								'height': '90%'
							});
					}
					var ifStart=true;
					if(startWait != null) {
						if(!confirm("退出当前游戏，重新开始？")) {
							ifStart=false;
						}
					}
					if(ifStart){
						startPlace();
					}				
				})
			});
			
			//放置卡片,启动
			function startPlace() {	
				$time.text(minute);
				var stop = clearTimeout(startWait);
				var stop2 = clearInterval(cacuTime);
				$('.box').remove();
				$table.text("");
				randomNum();
				alert("Ready Go!");
				changelook();

				startWait = setTimeout(function() {
					turnCard(0, $($allcard), -10);
					cacuTime = setInterval(function() {
						if(parseInt($($time).text()) == 0) {
							var word = "Game Over！";
							end(word);
							turnCard(0, $($allcard), 10);
						}
						else
						$($time).text(parseInt($($time).text()) - 1 + '');
					}, 1000);
					launched();
				}, timeStill);
			
			}
			
			//结束游戏，清除定时器
			function end(word) {

				var stop1 = clearInterval(cacuTime);
				var stop2 = clearTimeout(startWait);
				$table.text(word);
				startWait = null;

			}
			
			
			//切换模式
			function changelook() {
				for(var j = 0; j < cardNum; j++) {
					$box = $('<div></div>').addClass('box').css({
						'width': boxWidth + 'px',
						'height': boxHeight + 'px'
					});
					$card = $('<div></div>').addClass('card');
					$cardbg = $('<div></div>').addClass('cardbg');
					$box.appendTo($table);
					$card.appendTo($box);
					$cardbg.appendTo($box);
				}
				$allcard = $('.card');
				$allcardbg = $('.cardbg');
				for(var i = 0; i < $allcard.length; i++) {
					$($allcard[i]).css({
						'background-position-x': (-num[i] * 80) % 1040 + 'px',
						'background-position-y': parseInt((num[i] / 13)) * (-120) + 'px'
					});
					$($allcard[i]).attr("number", num[i] + "");

				}

			}			
			//翻转卡片
			function turnCard(degree, object, num) {
				$(object).css({
					'transform': 'rotateY(' + degree + 'deg)',
					'-webkit-transform': 'rotateY(' + degree + 'deg)',
					'z-index': num + ''

				});
			}			
			//随机生成卡片
			var cards = new Array;
			for(var i = 0; i < 52; i++) {
				cards.push(i);
			}
			function randomNum() {
				num.splice(0);
				console.log(cards.length);
				cards.sort(randomsort);
				for(var j = 0; j <cardNum; j++) {
					if(j>cardNum/2-1)
					{
						num[j] = cards[j-cardNum/2];
					}
					else
					num[j] = cards[j];
				}
				num.sort(randomsort);
			}
			function randomsort() {
				return Math.random() > 0.5 ? -1 : 1;
			}
			